<template>
  <div class="p-2">
    <ma-crud ref="crudRef" :columns="columns" :options="crud">
      <template #search-applyName="{ searchForm, component }">
        <a-input
          v-model.trim="searchForm[component.dataIndex]"
          :style="{ width: '240px' }"
          allow-clear
          placeholder="请输入业务名称"
        >
          <template #prefix>
            <icon-search />
          </template>
        </a-input>
      </template>
      <template #operationAfterExtend="{ record }">
        <a-link @click="handleDetail(record)">详情</a-link>
      </template>
    </ma-crud>
    <attact-info-table ref="attactInfoTableRef" />
  </div>
</template>

<script lang="ts" name="Attact" setup>
import { addAttactment, delAttactment, listAttactment } from "@/api/system/attact";
import AttactInfoTable from "@/views/system/attact/components/attact-info-table.vue";
const attactInfoTableRef = ref(AttactInfoTable);
const crud = reactive({
  id: "attactId",
  pk: "attactId",
  title: "附件查询",
  formLayout: "vertical",
  formOption: {
    width: 600,
    layout: [
      {
        formType: "grid",
        gutter: 16,
        cols: [
          { span: 12, formList: [{ dataIndex: "applyName" }] },
          { span: 12, formList: [{ dataIndex: "applyCode" }] },
          { span: 24, formList: [{ dataIndex: "remark" }] }
        ]
      }
    ]
  },
  api: listAttactment,
  showIndex: true,
  operationColumn: true,
  operationColumnAlign: "center",
  operationColumnWidth: 180,
  pageLayout: "normal",
  requestParams: { orderBy: "createTime", orderType: "desc" },
  add: { api: addAttactment, auth: ["system:attactment:add"], text: "新增", show: true },
  delete: { api: delAttactment, auth: ["system:attactment:delete"], text: "删除", show: true },
  edit: { api: delAttactment, auth: ["system:attactment:edit"], text: "编辑", show: true }
});
const columns = reactive([
  {
    title: "附件编号",
    dataIndex: "attactId",
    align: "center",
    hide: true
  },
  {
    title: "业务名称",
    dataIndex: "applyName",
    align: "center",
    search: true,
    commonRules: {
      required: true,
      message: "请输入业务名称"
    }
  },
  {
    title: "业务编码",
    dataIndex: "applyCode",
    align: "center",
    commonRules: {
      required: true,
      message: "请输入业务编码"
    }
  },
  {
    title: "描述",
    dataIndex: "remark",
    align: "center",
    formType: "textarea",
    autoSize: { minRows: 3, maxRows: 6 },
    maxLength: 200,
    showWordLimit: true,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "createTime",
    align: "center",
    addDisplay: false,
    editDisplay: false
  }
]);

const handleDetail = async (row?: any) => {
  const attactId = row?.attactId;
  attactInfoTableRef.value?.show(attactId);
};
</script>
